#ifndef _SUBJECT_H_  
#define _SUBJECT_H_  
#include <iostream>  
  
class Subject {  
public:  
    virtual void Request() = 0;  
    virtual ~Subject() {} // 添加虚析构函数以确保正确析构  
};  
  
class RealSubject : public Subject {  
public:  
    void Request() override {  
        std::cout << "真实的请求" << std::endl;  
    }  
};  
  
class Proxy : public Subject {  
private:  
    RealSubject* realSubject;  
  
public:  
    Proxy() : realSubject(nullptr) {}  
  
    void Request() override {  
        if (nullptr == this->realSubject) {  
            this->realSubject = new RealSubject();  
        }  
        this->realSubject->Request();  
    }  
  
    ~Proxy() override {  
        delete realSubject; // 在析构函数中删除真实对象  
    }  
};  
  
#endif